{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "73bd968b-d970-4a05-94ef-4e7abf990827",
   "metadata": {},
   "source": [
    "Chapter 01\n",
    "\n",
    "# 无理数\n",
    "Book_3《数学要素》 | 鸢尾花书：从加减乘除到机器学习 (第二版)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "080d7f5f-1279-44de-b938-3606bf8662ab",
   "metadata": {},
   "source": [
    "该代码主要使用Python的`math`库来输出一些常见的数学常数：圆周率$\\pi$、自然对数的底数$e$，以及数值$2$的平方根$\\sqrt{2}$。\n",
    "\n",
    "首先，代码导入`math`库，这是Python内置的一个数学模块，提供了多种数学常量和函数。接着，代码依次输出了以下三个常数的数值：\n",
    "\n",
    "1. **圆周率$\\pi$**：圆周率$\\pi$的值定义为一个圆的周长与直径的比值，其数值大约为$3.14159$。在代码中，`math.pi`用于访问此常量。\n",
    "\n",
    "   $$\n",
    "   \\pi \\approx 3.14159\n",
    "   $$\n",
    "\n",
    "2. **自然常数$e$**：$e$是自然对数的底数，大约为$2.71828$，在数学和物理学中常用于描述指数增长和衰减过程。代码中的`math.e`返回此常量。\n",
    "\n",
    "   $$\n",
    "   e \\approx 2.71828\n",
    "   $$\n",
    "\n",
    "3. **平方根$\\sqrt{2}$**：这是一个无理数，表示数值$2$的平方根。平方根的定义是一个数乘以自身等于$2$，即$\\sqrt{2} \\times \\sqrt{2} = 2$，其近似值为$1.41421$。代码中的`math.sqrt(2)`计算并返回该值。\n",
    "\n",
    "   $$\n",
    "   \\sqrt{2} \\approx 1.41421\n",
    "   $$\n",
    "\n",
    "总结而言，该代码通过`math`库提供的接口直接输出$\\pi$、$e$和$\\sqrt{2}$的数值，展示了Python如何使用数学常数和基本函数。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfa721f3-0190-46be-9cd7-c427ec877ed2",
   "metadata": {},
   "source": [
    "## 导入数学库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bf7a52bb-eacc-4448-94e2-a8110878c277",
   "metadata": {},
   "outputs": [],
   "source": [
    "import math  # 导入math库"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b7670bf-e909-487b-9f1a-2f15acabfd81",
   "metadata": {},
   "source": [
    "## 打印数学常量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8ca981a5-3712-40a2-a306-ed653115a0b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pi =  3.141592653589793\n"
     ]
    }
   ],
   "source": [
    "print('pi = ', math.pi)  # 输出π的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9a45dc7f-6b95-48b8-98d2-0fcda1b8a59c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "e =  2.718281828459045\n"
     ]
    }
   ],
   "source": [
    "print('e = ', math.e)  # 输出自然常数e的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cf32cf91-9028-4c75-bf16-cab134c3cd95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sqrt(2) =  1.4142135623730951\n"
     ]
    }
   ],
   "source": [
    "print('sqrt(2) = ', math.sqrt(2))  # 输出2的平方根"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85a80909-2aac-49ed-bb7a-f8cc6b80ee7d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecd322f4-f919-4be2-adc3-69d28ef25e69",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
